VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "VBModuleFileReader"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Implements IVBModuleReader

Private ts As TextStream
Private mFileName As String
Private mFileSize As String

Private Property Get IVBModuleReader_AtEndOfStream() As Boolean
    IVBModuleReader_AtEndOfStream = AtEndOfStream
End Property

Private Sub IVBModuleReader_ConstructFrom(rawMaterial As Variant)
    OpenFilePath CStr(rawMaterial)
End Sub

Private Property Get IVBModuleReader_FileName() As String
    IVBModuleReader_FileName = mFileName
End Property

Private Property Get IVBModuleReader_FileSize() As Long
    IVBModuleReader_FileSize = mFileSize
End Property

Private Property Get IVBModuleReader_ModuleType() As vbModuleType

    Select Case LCase(Mid(mFileName, InstrRev(mFileName, ".") + 1))
    Case "frm"
        IVBModuleReader_ModuleType = vbmtForm
    Case "cls"
        IVBModuleReader_ModuleType = vbmtclass
    Case "bas"
        IVBModuleReader_ModuleType = vbmtmodule
    End Select

End Property

Private Function IVBModuleReader_NextVBLine() As VBLine
    Set IVBModuleReader_NextVBLine = NextVBLine
End Function

Private Sub OpenFilePath(filePath As String)

Dim fso As FileSystemObject

    Set fso = New FileSystemObject
    
    mFileName = fso.GetFileName(filePath)
    mFileSize = fso.GetFile(filePath).Size

    Set ts = fso.OpenTextFile(filePath, ForReading)

End Sub

Private Function NextVBLine() As VBLine

    Set NextVBLine = New VBLine

    NextVBLine.Text = ts.ReadLine

    Do While (Not ts.AtEndOfStream And NextVBLine.HasContinuation)
        NextVBLine.AddText ts.ReadLine
    Loop

End Function

Private Property Get AtEndOfStream() As Boolean
    AtEndOfStream = ts.AtEndOfStream
End Property

